﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Common;
using System.Data;
using System.Collections;


namespace System
{
    public interface IDalData
    {

        #region 基本方法

        /// <summary>
        /// 开启事务处理
        /// </summary>
        void OpenTransaction();

        /// <summary>
        /// 判断符合条件的数据是否存在
        /// </summary>
        /// <param name="filter">条件</param>
        /// <param name="tableName">数据表名</param>
        /// <param name="parameters">对应参数</param>
        /// <returns>存在返回true,不存在返回false</returns>
        bool Exists(string filter, string tableName, List<DBParameter> parameters);

        /// <summary>
        /// 查询符合条件的记录数
        /// </summary>
        /// <param name="filter">查询条件</param>
        /// <param name="tableName">数据表</param>
        /// <param name="parameters">对应参数</param>
        /// <returns>返回符合条件的记录数</returns>
        int GetCount(string filter, string tableName, List<DBParameter> parameters);

        /// <summary>
        /// 判断符合条件的数据是否存在
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <returns>存在返回true,不存在返回false</returns>
        bool Exists(List<DbParameter> parameters, string filter, string tableName);

        /// <summary>
        /// 查询符合条件的记录数
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回符合条件的记录数</returns>
        int GetCount(List<DbParameter> parameters, string filter, string tableName);

        #endregion

        #region 删除

        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(string filter, string tableName, List<DBParameter> parameters);

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(BaseModel model, string tableName);

        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="primaryKeyInfo">主键信息</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(DBParameter primaryKeyInfo, string tableName);


        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(List<DBParameter> parameters, string tableName);

        /// <summary>
        /// 删除集合中的对象
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(ArrayList list, string tableName);      

        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(List<DbParameter> parameters, string filter, string tableName);

        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(string tableName, List<DbParameter> parameters);
       

        #endregion

        #region 更新

        /// <summary>
        /// 修改符合条件记录的指定字段
        /// </summary>
        /// <param name="fieldName">字段名</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <param name="value">值</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(string fieldName, string filter, string tableName, object value, List<DBParameter> parameters);

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(BaseModel model, string fields, string tableName);


        /// <summary>
        /// 修改对象集合
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(ArrayList list, string fields, string tableName);

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(BaseModel model, string fields, string filter, string tableName, List<DBParameter> parameters);

        /// <summary>
        /// 修改符合条件记录的指定字段
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="fieldName">字段名</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <param name="value">值</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(List<DbParameter> parameters, string fieldName, string filter, string tableName, object value);

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(List<DbParameter> parameters, BaseModel model, string fields, string filter, string tableName);   

        #endregion

        #region GetTable

        /// <summary>
        /// 执行SQL语句，并返回记录到DataTable
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(string sql);

        /// <summary>
        /// 执行SQL语句，并返回记录到DataTable
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(string sql, List<DBParameter> parameters);

        /// <summary>
        /// 获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="tableName">表名</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters);

        /// <summary>
        /// 分页形式获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">总记录数。为-1时，将从数据库获取该值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="tableName">表名</param>
        /// <param name="primaryKey"></param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, string primaryKey, List<DBParameter> parameters);      

        /// <summary>
        /// 执行SQL语句，并返回记录到DataTable
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="sql">SQL语句</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(List<DbParameter> parameters, string sql);

        /// <summary>
        /// 获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(List<DbParameter> parameters, string fields, string filter, string sorts, string tableName);

        /// <summary>
        /// 分页形式获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">总记录数。为-1时，将从数据库获取该值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="tableName">表名</param>
        /// <param name="primaryKey"></param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(List<DbParameter> parameters, int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, string primaryKey);

        /// <summary>
        /// 获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="sqlInfo">封装的筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(SqlInfo sqlInfo, List<DBParameter> parameters);

        /// <summary>
        /// 分页形式获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="pageInfo">封装的分页数据筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(PageInfo pageInfo, List<DBParameter> parameters);

        /// <summary>
        /// 获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="sqlInfo">封装的筛选信息</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(List<DbParameter> parameters, SqlInfo sqlInfo);

        /// <summary>
        /// 分页形式获取符合条件的记录到DataTable
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="pageInfo">封装的分页数据筛选信息</param>
        /// <returns>返回受影响的记录数</returns>
        DataTable GetDataTable(List<DbParameter> parameters, PageInfo pageInfo);

        #endregion

        #region 新增

        /// <summary>
        /// 新增对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Insert(BaseModel model, string fields, string tableName);

        /// <summary>
        /// 新增对象集合
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int Insert(ArrayList list, string fields, string tableName);

        #endregion

        #region InsertOrUpdate

        /// <summary>
        /// 新增或修改对象，如对象存在则修改，反之新增
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int InsertOrUpdate(BaseModel model, string fields, string tableName);

        /// <summary>
        /// 修改或修改对象集合，如集合中对象存在则修改，反之新增
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回受影响的记录数</returns>
        int InsertOrUpdate(ArrayList list, string fields, string tableName);
       
        #endregion        

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(BaseModel model);

        /// <summary>
        /// 删除集合中的对象
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(ArrayList list);

        /// <summary>
        /// 新增对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int Insert(BaseModel model, string fields);

        /// <summary>
        /// 新增集合中的对象
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int Insert(ArrayList list, string fields);
   
        /// <summary>
        /// 新增或修改对象，如对象存在则修改，反之新增
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int InsertOrUpdate(BaseModel model, string fields);

        /// <summary>
        /// 新增或修改集合中的对象，如对象存在则修改，反之新增
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int InsertOrUpdate(ArrayList list, string fields);

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(BaseModel model, string fields);

        /// <summary>
        /// 修改集合中对象
        /// </summary>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(ArrayList list, string fields);

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(BaseModel model, string fields, string filter, List<DBParameter> parameters);

        /// <summary>
        /// 修改集合中对象
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(List<DbParameter> parameters, BaseModel model, string fields, string filter);
    }
}
